package com.web.servlet.db;

import com.web.servlet.bean.Player;
import com.web.servlet.dao.DBConnect;
import com.web.servlet.dao.DBPoolManager;
import com.web.servlet.utils.TimeServerUtil;
import com.web.servlet.utils.Utils;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Types;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;


public class GameDaoImpl extends StrategyBaseDao implements IGameDao {
	/*@Override
	public int addBackPlayer(BackPlayer backPlayer) {
		return 0;
	}*/

	/*@Override
	public BackPlayer getBackPlayerByAccount(String user_account) {
		{
			BackPlayer player =null;
			try
			{
				Connection con = DBConnect.connDataBase();

				String currTime = Utils.getCurrTime();

				CallableStatement statement =  con.prepareCall("{call t_daili_user_info(?)}");
				statement.setString(1, user_account);
				*//*statement.setString(2, password);
				statement.setString(3, strIp);*//*
				//statement.setString(4, currTime);
				ResultSet rs= statement.executeQuery();

				while(rs.next())
				{
					player =new BackPlayer();
					player.setId(rs.getInt("userId"));
					*//*player.setName(rs.getString("userName"));
					player.setNickName(rs.getString("userNikeName"));
					player.setCoin(rs.getInt("userCoin"));
					player.setHeadImgIndex(rs.getInt("headImgIndex"));
					player.setSex(rs.getInt("userSex"));
					player.setSex(rs.getInt("userDiamond"));
					player.setSzWord(rs.getString("userWord"));*//*
					break;
				}
				DBPoolManager.closeConn(con);
				if (rs!=null)
					rs.close();
				if (con!=null)
					con.close();
				if (statement!=null)
					statement.close();
			}
			catch(Exception e)
			{
				e.printStackTrace();
			}

			return player;
		}
	}*/

	@Override
	public int addGamePlayer(Player player) {
		return 0;
	}

	@Override
	public Player getGamePlayerByAccount(String account) {
		return null;
	}
/*@Override
	public boolean addItemLog(List<ItemLog> infos) {
		if (infos == null || infos.size() == 0)
			return true;
		List<String> sqlComm = new ArrayList<String>();
		for (ItemLog info : infos) {
			if (info != null) {
				sqlComm.add(String.format(
						" INSERT INTO log_item(player_id,item_id,change_id,change_itemnum,now_nownum,change_date) "
								+ "VALUE (%s,%s,%s,%s,%s,'%s')", info.getPlayerID(), info.getItemID(), info
								.getChangeID(), info.getChangeItemNum(), info.getNowItemNum(), info.getChangeDate()));
			}
		}
		return sqlBatch("log_item", sqlComm);
	}*/

	public boolean addLoginLog(long playerId, int isNewPlayer,String channel) {
		if (playerId == 0) {
			return false;
		}
		boolean result = false;
			String sql = " INSERT INTO log_login(`playerId`, `is_new`, `login_time`, `channel`)  VALUES(?,?,?,?);";
			Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
			para.put(1, new DbParameter(Types.INTEGER, playerId));
			para.put(2, new DbParameter(Types.INTEGER, isNewPlayer));
			para.put(3, new DbParameter(Types.TIMESTAMP, TimeServerUtil.getSysteCurTime()));
			para.put(4, new DbParameter(Types.VARCHAR, channel));
			result = execNoneQuery(sql, para) > -1 ? true : false;
		
		return result;
	}

	public boolean addChargeLog(long playerId, int chargeNum, int chargeType,String channel) {
		if (playerId == 0) {
			return false;
		}
		boolean result = false;
			String sql = " INSERT INTO log_charge(`playerId`, `charge_num`, `charge_type`, `create_date`, `channel`)  VALUES(?,?,?,?,?);";
			Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
			para.put(1, new DbParameter(Types.INTEGER, playerId));
			para.put(2, new DbParameter(Types.INTEGER, chargeNum));
			para.put(3, new DbParameter(Types.INTEGER, chargeType));
			para.put(4, new DbParameter(Types.TIMESTAMP, TimeServerUtil.getSysteCurTime()));
			para.put(5, new DbParameter(Types.VARCHAR, channel));
			result = execNoneQuery(sql, para) > -1 ? true : false;
		
		return result;
	}

	public boolean addOnlineLog(int onlineNum) {
		boolean result = false;
			String sql = " INSERT INTO log_online(`oline_num`, `create_time`)  VALUES(?,?);";
			Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
			para.put(1, new DbParameter(Types.INTEGER, onlineNum));
			para.put(2, new DbParameter(Types.TIMESTAMP, TimeServerUtil.getSysteCurTime()));
			result = execNoneQuery(sql, para) > -1 ? true : false;
		
		return result;
	}

	public boolean addPlayerNum(Date timeNow, int num) {
		boolean result = false;
		String sql = " INSERT INTO log_playernum(`player_num`, `create_date`)  VALUES(?,?);";
		Map<Integer, DbParameter> para = new HashMap<Integer, DbParameter>();
		para.put(1, new DbParameter(Types.INTEGER, num));
		para.put(2, new DbParameter(Types.TIMESTAMP, timeNow));
		result = execNoneQuery(sql, para) > -1 ? true : false;
	
	return result;
	}

	
	
	
}
